x = int(input()) 

d = x % 10 
c = x // 10 % 10 
b = x // 100 % 10 
a = x // 1000 
ma = 0
count = 0 

for i in range(1,x +1): 
    if x%i == 0: 
        count = count+1 
if count == 2: 
    if ma < x:
        ma = x
        
count = 0 
kon1=b*100+c*10+d 
for i in range(1,kon1 +1): 
    if kon1%i == 0: 
        count = count+1 
if count == 2: 
    if ma < kon1:
        ma = kon1
        
count = 0 
kon2=a*100+b*10+c 
for i in range(1,kon2 +1): 
    if kon2%i == 0: 
        count = count+1 
if count == 2: 
    if ma < kon2:
        ma = kon2
        
count = 0 
kon3=c*10+d  
for i in range(1,kon3 +1): 
    if kon3%i == 0: 
        count = count+1 
if count == 2: 
    if ma < kon3:
        ma = kon3
        
count = 0 
kon4=b*10+c 
for i in range(1,kon4 +1): 
    if kon4%i == 0: 
        count = count+1 
if count == 2: 
    if ma < kon4:
        ma = kon4

count = 0 
kon5=a*10+b
for i in range(1,kon5 +1): 
    if kon5%i == 0: 
        count = count+1 
if count == 2: 
    if ma < kon5:
        ma = kon5
        
count = 0 
kon6=a 
for i in range(1,kon6 +1): 
    if kon6%i == 0: 
        count = count+1 
if count == 2: 
    if ma < kon6:
        ma = kon6

count = 0 
kon7=b 
for i in range(1,kon7 +1): 
    if kon7%i == 0: 
        count = count+1 
if count == 2: 
    if ma < kon7:
        ma = kon7
        
count = 0 
kon8=c 
for i in range(1,kon8 +1): 
    if kon8%i == 0: 
        count = count+1 
if count == 2: 
    if ma < kon8:
        ma = kon8
        
count = 0 
kon1=b*100+c*10+d 
for i in range(1,kon1 +1): 
    if kon1%i == 0: 
        count = count+1 
if count == 2: 
    if ma < kon1:
        ma = kon1
        
count = 0 
kon9=d
for i in range(1,kon9 +1): 
    if kon9%i == 0: 
        count = count+1 
if count == 2: 
    if ma < kon9:
        ma = kon9
if len(str(x))!=4:
  ma=0
if x < 0:
  ma=0
print(ma)
